#include <iostream>
using std::cout;
using std::endl;

class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + "
            << _image << "i"
            << endl;
    }
    friend Complex operator+(const Complex & c1,const Complex & c2);
private:
    int _real;
    int _image;
};

//友元函数形式实现重载
Complex operator+(const Complex & c1,const Complex & c2)
{
    return Complex(c1._real + c2._real,
                   c1._image + c2._image);

}

/* Complex operator+(const Complex & cx,int x){} */

//会导致1 + 1 = 0，不允许定义
/* int operator+(int x,int y){ */
/*     return x - y; */
/* } */

void test0(){
    int x = 1, y = 2;
    /* &(x + y); */
    cout << x + y << endl;


    Complex cx1(1,2);
    Complex cx2(3,4);
    //operator=
    /* cx1 = cx2; */

    cx1.print();
    cx2.print();
    
    /* add(cx1,cx2).print(); */
    /* Complex cx3 = add(cx1,cx2); */
    /* cx3.print(); */

    //本质形式
    /* Complex cx3 = operator+(cx1,cx2); */
    Complex cx3 = cx1 + cx2;
    cx3.print();
}

void test1(){
    int num = 10;
    cout << sizeof(num) << endl;
    cout << sizeof(int) << endl;
    cout << sizeof num << endl;
    /* cout << sizeof int << endl;//error */
}

int main(void){
    test0();
    return 0;
}
